﻿package Framework.Protocol.CDFProtocol
{
    import flash.utils.*;

    public class ProtocolHead extends Object
    {
        public var magic1:int;
        public var magic2:int;
        public var magic3:int;
        public var magic4:int;
        public var protocol:int;
        public var encoding:int;
        public var reserve1:int;
        public var reserve2:int;
        public var messageSize:int;
        public var verifyResult:int;
        public var messageType:int;
        public var compressionStatus:int;
        public var encryptStatus:int;
        public var encryptAddLength:int;
        public static const CDF_PROTOCOL_INT_VERSION:int = 1;
        public static const CDF_ENCODING_INT_VERSION:int = 1;
        public static const CDF_PROTOCOL_HEAD_SIZE:int = 24;
        public static const CDF_PROTOCOL_MAX_SIZE:int = 512000;

        public function ProtocolHead()
        {
            this.magic1 = String("C").charCodeAt();
            this.magic2 = String("D").charCodeAt();
            this.magic3 = String("E").charCodeAt();
            this.magic4 = String("!").charCodeAt();
            this.messageType = 0;
            this.compressionStatus = 0;
            this.reserve1 = 0;
            this.reserve2 = 0;
            this.protocol = CDF_PROTOCOL_INT_VERSION;
            this.encoding = CDF_ENCODING_INT_VERSION;
            this.messageSize = 0;
            this.verifyResult = 0;
            this.encryptStatus = 0;
            this.encryptAddLength = 0;
            return;
        }// end function

        public function __read(param1:ByteArray) : void
        {
            this.magic1 = param1.readByte();
            this.magic2 = param1.readByte();
            this.magic3 = param1.readByte();
            this.magic4 = param1.readByte();
            this.protocol = param1.readByte();
            this.encoding = param1.readByte();
            this.reserve1 = param1.readByte();
            this.reserve2 = param1.readByte();
            this.messageSize = param1.readInt();
            this.verifyResult = param1.readInt();
            this.messageType = param1.readByte();
            this.compressionStatus = param1.readByte();
            this.encryptStatus = param1.readByte();
            this.encryptAddLength = param1.readByte();
            return;
        }// end function

        public function __write(param1:ByteArray) : void
        {
            param1.writeByte(this.magic1);
            param1.writeByte(this.magic2);
            param1.writeByte(this.magic3);
            param1.writeByte(this.magic4);
            param1.writeByte(this.protocol);
            param1.writeByte(this.encoding);
            param1.writeByte(this.reserve1);
            param1.writeByte(this.reserve2);
            param1.writeInt(this.messageSize);
            param1.writeInt(this.verifyResult);
            param1.writeByte(this.messageType);
            param1.writeByte(this.compressionStatus);
            param1.writeByte(this.encryptStatus);
            param1.writeByte(this.encryptAddLength);
            return;
        }// end function

    }
}
